package com.hxs.email;

import com.hxs.email.config.UserListConfig;
import com.hxs.email.task.GradeQueryTask;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.nio.file.Paths;

@SpringBootApplication
@EnableScheduling
@RequiredArgsConstructor
public class EmailApplication {

    private final UserListConfig userListConfig;
    private final GradeQueryTask gradeQueryTask;
    public static void main(String[] args) {

        SpringApplication.run(EmailApplication.class, args);

        // 自动兼容.yml/.yaml/.properties
//        String configPath = "file:" +
//                Paths.get("").toAbsolutePath()
//                        .toUri().getPath(); // URI格式兼容所有系统
//
//        new SpringApplicationBuilder(EmailApplication.class) .properties(
//                        "spring.config.location=" + configPath,
//                        "spring.config.name=application", // 固定加载application.*
//                        "spring.config.import=optional:file:./override.yml" // 可追加额外配置
//                )
//                .bannerMode(Banner.Mode.CONSOLE)
//                .run(args);

    }

    @PostConstruct
    private void usersInit(){
        userListConfig.getUsers().forEach(gradeQueryTask::addUser);
        gradeQueryTask.gradeQuerySchedule();
    }

}
